package NC;

import java.util.Arrays;

public class NC12 {
    public TreeNode reConstructBinaryTree(int [] pre,int [] in) {
        if(pre.length == 0) return null;
        int val = pre[0];
        int index =0;
        for (; index < pre.length; index++) {
            if(in[index]==val) break;
        }
        TreeNode root = new TreeNode(val);
        root.left = reConstructBinaryTree(Arrays.copyOfRange(pre,1,index+1),Arrays.copyOfRange(in,0,index));
        root.right = reConstructBinaryTree(Arrays.copyOfRange(pre,index+1,pre.length),Arrays.copyOfRange(in,index+1,pre.length));
        return root;

    }

}
